# /usr/bin/python
# encoding:utf-8
from pylab import *
import os


class GetRes(object):
    def __init__(self, package_name, find_types):
        self.package_name = package_name
        self.find_types = find_types

    def get_cpu(self, find_types, package_name):
        cpu_str = os.popen(("adb shell dumpsys cpuinfo | %s  %s") % (find_types, package_name))
        cpu_list = cpu_str.readline().split()
        print(cpu_list)
        cpu = cpu_list[0].replace("%", "")
        print(cpu)
        return cpu

    def get_mem(self, find_types, package_name):
        mem_result = os.popen(("adb shell dumpsys meminfo  | %s  %s") % (find_types, package_name))
        mem_list = mem_result.readline().split()
        mem = mem_list[0].replace("K:", "")
        print(mem)
        return mem

    def get_bytes_uid(self,find_types, package_name):
        uid_str = os.popen(("adb shell ps | %s %s") % (find_types, package_name))
        uid_list = uid_str.readline().split()
        print("uid :" + uid_list[1])
        return uid_list[1]

    def get_bytes(self, find_types):
        bytes_list = []
        bytes_result = os.popen(("adb shell cat /proc/%s/net/dev | %s wlan0") % (GetRes.get_bytes_uid(), find_types))
        bytes_value = bytes_result.readline()
        recv = int(bytes_value.split()[1])
        send = int(bytes_value.split()[9])
        bytes_list.append(recv)
        bytes_list.append(send)
        print(recv / 1024)
        print(send / 1024)
        return recv, send, bytes_list, recv - send





